home *** CD-ROM | disk | FTP | other *** search
- Path: Belgium.EU.net!box!pahint
- From: pahint@eunet.be (Pieter Hintjens)
- Newsgroups: comp.lang.c
- Subject: Re: Universal include file
- Date: 25 Feb 1996 13:25:36 GMT
- Organization: EUnet Belgium, Leuven, Belgium
- Message-ID: <4gpo0g$hve@news.Belgium.EU.net>
- References: <4gnjea$30m@news.Belgium.EU.net> <4gpfh5$fmo@news.Belgium.EU.net>
- NNTP-Posting-Host: box.eunet.be
- X-Newsreader: TIN [version 1.2 PL2]
-
- This is version 1.01 of the Universal Include File.. Ta-taaa...!
- Changes from version 1.00:
- - __UTYPE_xxx symbol for UNIX version
- - removed some of the more personal macros (AND, OR, strlast,...)
- - byte = 8 bits, dbyte = 16 bits, qbyte = 32 bits
-
- --
- Pieter A. Hintjens
-
-
- /*===========================================================================*
- * *
- * prelude.h Universal header file for C programming *
- * *
- * Written: 93/03/29 Pieter Hintjens <ph@mymail.com> *
- * Revised: 96/02/25 Version 1.01 *
- * *
- * This header encapsulates all generally-useful include files and defines *
- * various useful things. To use, specify as first include file in code. *
- * *
- * Contributors & critics: *
- * Gordon Burditt <gordon@sneaky.lerctr.org> 25 Feb 1996 *
- * Steve Leibel <stevel@coastside.net> 25 Feb 1996 *
- * Guus Leeuw jr. <guusl@eiffel.com> 25 Feb 1996 *
- * *
- * Copyright (c) 1991-96 Pieter A. Hintjens. May be freely distributed. *
- *===========================================================================*/
-
- #ifndef _PRELUDE_INCLUDED /* Allow multiple inclusions */
- #define _PRELUDE_INCLUDED
-
-
- /*- Generally-useful include files ------------------------------------------*/
-
- #include <ctype.h>
- #include <limits.h>
- #include <stdarg.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include <signal.h>
- #include <errno.h>
- #include <fcntl.h>
-
-
- /*- Establish the compiler and computer system ------------------------------*/
- /*
- * Defines one or more of these symbols, for use in any non-portable
- * code:
- *
- * __WINDOWS__ Microsoft C/C++ with Windows calls
- * __MSDOS__ File system is MS-DOS
- * __VMS__ System is VAX/VMS or Alpha/OpenVMS
- * __UNIX__ System is UNIX
- * __MAC__ System is Mac/OS
- *
- * __32BIT__ OS/compiler is 32 bits
- * __64BIT__ OS/compiler is 64 bits
- *
- * When __UNIX__ is defined, we also define exactly one of these:
- *
- * __UTYPE_AUX Apple AUX
- * __UTYPE_DECALPHA Digital UNIX (Alpha)
- * __UTYPE_HPUX HP/UX
- * __UTYPE_IBMAIX IBM RS/6000 AIX
- * __UTYPE_LINUX Linux
- * __UTYPE_MIPS MIPS (BSD 4.3/System V mixture)
- * __UTYPE_NETBSD NetBSD
- * __UTYPE_NEXT NeXT
- * __UTYPE_SCO SCO Unix
- * __UTYPE_SUNOS SunOS
- * __UTYPE_SUNSOLARIS Sun Solaris
- * __UTYPE_GENERIC Any other UNIX
- */
-
- #define __32BIT__ /* Assume 32-bit OS/compiler */
-
- #if (defined (WIN32) || defined (WINDOWS))
- # undef __WINDOWS__
- # define __WINDOWS__
- # undef __MSDOS__
- # define __MSDOS__
- #endif
-
- /* MSDOS is Microsoft C */
- /* _MSC_VER is Microsoft C */
- /* __TURBOC__ is Borland Turbo C */
- #if (defined (MSDOS) || defined (_MSC_VER) || defined (__TURBOC__))
- # undef __MSDOS__
- # define __MSDOS__
- #endif
-
- /* VMS is VAX C (VAX/VMS) */
- /* __VMS is Dec C (Alpha/OpenVMS) */
- /* __vax__ is gcc */
- #if (defined (VMS) || defined (__VMS) || defined (__vax__))
- # undef __VMS__
- # define __VMS__
- #endif
-
- /* unix is SunOS */
- /* __unix__ is gcc */
- /* _POSIX_SOURCE is various UNIX systems, maybe also VAX/VMS */
- #if (defined (unix) || defined (__unix__) || defined (_POSIX_SOURCE))
- # if (!defined (__VMS__))
- # undef __UNIX__
- # define __UNIX__
- # if (defined (__alpha)) /* Digital UNIX is 64-bit */
- # undef __32BIT__
- # define __64BIT__
- # endif
- # endif
- #endif
-
- /* Try to define a __UTYPE_xxx symbol... */
- #if (defined __UNIX__)
- # if (defined (_AUX))
- # define __UTYPE_AUX
- # elif (defined (__alpha))
- # define __UTYPE_DECALPHA
- # elif (defined (__hpux))
- # define __UTYPE_HPUX
- # elif (defined (_AIX) || defined (AIX))
- # define __UTYPE_IBMAIX
- # elif (defined (linux))
- # define __UTYPE_LINUX
- # elif (defined (Mips))
- # define __UTYPE_MIPS
- # elif (defined (NetBSD))
- # define __UTYPE_NETBSD
- # elif (defined (NeXT))
- # define __UTYPE_NEXT
- # elif (defined (sco))
- # define __UTYPE_SCO
- # elif (defined (SUNOS))
- # define __UTYPE_SUNOS
- # elif (defined (SOLARIS))
- # define __UTYPE_SUNSOLARIS
- # else
- # define __UTYPE_GENERIC
- # endif
- #endif
-
- /* Untested */
- #if (defined (_MAC))
- # undef __MAC__
- # define __MAC__
- #endif
-
-
- /*- System-specific include files -------------------------------------------*/
-
- #if (defined (__TURBOC__)) /* Borland Turbo-C uses this */
- # include <alloc.h> /* name for its include file */
- #else
- # include <malloc.h>
- #endif
-
- #if (defined (__WINDOWS__)) /* When __WINDOWS__ is defined, */
- # include <windows.h> /* so is __MSDOS__ */
- #endif
-
- #if (defined (__MSDOS__))
- # include <dos.h>
- # include <io.h>
- # include <fcntl.h>
- # include <sys\types.h>
- # include <sys\stat.h>
- #endif
-
- #if (defined (__UNIX__))
- # include <netdb.h>
- # include <unistd.h>
- # include <netinet/in.h>
- # include <sys/types.h>
- # include <sys/param.h>
- # include <sys/socket.h>
- # include <sys/time.h>
- # include <sys/stat.h>
- /* Specific includes for UNIX varieties */
- # if defined (__UTYPE_IBMAIX)
- # include <sys/select.h>
- # endif
- #endif
-
- #if (defined (__VMS__))
- # include <types.h>
- # include <netdb.h>
- # include <unixio.h>
- # include <in.h>
- # include <param.h>
- # include <socket.h>
- # include <time.h>
- # include <stat.h>
- #endif
-
-
- /*- Data types --------------------------------------------------------------*/
-
- typedef int Bool; /* Boolean TRUE / FALSE value */
- typedef unsigned char byte; /* Single unsigned byte = 8 bits */
- typedef unsigned short dbyte; /* Double byte = 16 bits */
- #if (defined (__32BIT__))
- typedef unsigned long qbyte; /* Quad byte = 32 bits */
- #else
- typedef unsigned int qbyte; /* Quad byte = 32 bits */
- #endif
- typedef void (*function) (void); /* Address of simple function */
- #define local static void /* Shorthand for local functions */
-
-
- /*- Check compiler data type sizes ------------------------------------------*/
-
- #if (UCHAR_MAX != 0xFF)
- # error "Cannot compile: must change definition of 'byte'."
- #endif
- #if (USHRT_MAX != 0xFFFFU)
- # error "Cannot compile: must change definition of 'dbyte'."
- #endif
- #if (defined (__32BIT__))
- # if (ULONG_MAX != 0xFFFFFFFFUL)
- # error "Cannot compile: must change definition of 'qbyte'."
- # endif
- #else
- # if (UINT_MAX != 0xFFFFFFFFU)
- # error "Cannot compile: must change definition of 'qbyte'."
- # endif
- #endif
-
-
- /*- Pseudo-functions --------------------------------------------------------*/
-
- #define until(expr) while (!(expr)) /* do { ... } until (expr) */
- #define streq(s1, s2) (!strcmp ((s1), (s2)))
- #define strneq(s1, s2) (strcmp ((s1), (s2)))
- #define strused(s) (*(s) != 0)
- #define strnull(s) (*(s) == 0)
- #define strclr(s) (*(s) = 0)
-
- #define bit_msk(bit) (1 << (bit))
- #define bit_set(x, bit) ((x) |= bit_msk (bit))
- #define bit_clr(x, bit) ((x) &= ~bit_msk (bit))
- #define bit_tst(x, bit) ((x) & bit_msk (bit))
-
- #define tblsize(x) (sizeof (x) / sizeof ((x) [0]))
- #define tbllast(x) (x [tblsize (x) - 1]);
-
- #if (defined (random))
- # undef random
- # undef randomize
- #endif
- #if (defined (min))
- # undef min
- # undef max
- #endif
-
- #if (defined (__32BIT__))
- #define random(num) (int) ((long) rand () % (num))
- #else
- #define random(num) (int) ((int) rand () % (num))
- #endif
- #define randomize() srand ((unsigned) time (NULL))
- #define min(a,b) (((a) < (b))? (a): (b))
- #define max(a,b) (((a) > (b))? (a): (b))
-
-
- /*- ASSERT and debugging ----------------------------------------------------*/
-
- #if (defined (DEBUG))
- /* Define _Assert function here locally */
- local _Assert (char *File, unsigned Line)
- {
- fflush (stdout);
- fprintf (stderr, "\nAssertion failed: %s, line %u\n", File, Line);
- fflush (stderr);
- abort ();
- }
- # define ASSERT(f) \
- if (f) \
- ; \
- else \
- _Assert (__FILE__, __LINE__)
- #else
- # define ASSERT(f)
- #endif
-
-
- /*- Boolean operators and constants -----------------------------------------*/
-
- #if (defined (TRUE))
- # undef TRUE
- # undef FALSE
- #endif
- #define TRUE (1==1)
- #define FALSE (1==0)
-
-
- /*- Symbolic constants ------------------------------------------------------*/
-
- #define FORK_ERROR -1 /* Return codes from fork() */
- #define FORK_CHILD 0
- #if (!defined (LINE_MAX))
- # define LINE_MAX 255
- #endif
-
-
- /*- System-specific definitions ---------------------------------------------*/
-
- #if (defined (__VMS__))
- # define RET_OKAY 1 /* Return codes for main() */
- # define RET_ERROR 0 /* VMS does it its own way. */
- #else
- # define RET_OKAY 0 /* On non-VMS systems 0 is okay, */
- # define RET_ERROR 1 /* and 1 is an error. */
- #endif
-
- #endif /* Include PRELUDE.H */
-